<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>各专业学年课程表安排</title>
    {% load static %}
    <link href="{% static './layui/css/layui.css' %}" rel="stylesheet">
    <script src="{% static './layui/layui.js' %}"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body style="padding: 50px">
<div id="ID-tree-demo-showLine"></div>
</body>
<script>
layui.use(function(){
  var tree = layui.tree;
  var _data = [];
  $.ajax({
        method: "POST",
        url: "{%url 'xyss_admin:majorTreeApi' %}",
        data: {
            "major_id":{{major_id}}
        },
        success: function (res) {
            if(res['code'] == 0){
                layer.msg(res['msg']);
                _data = res['data']
                tree.render({
                    elem: '#ID-tree-demo-showLine',
                    data: _data,
                    showLine: false,  // 是否开启连接线
                    click: function(obj){
                        console.log(obj.data); //得到当前点击的节点数据
                        console.log(obj.state); //得到当前节点的展开状态：open、close、normal
                        console.log(obj.elem); //得到当前节点元素
                        console.log(obj.data.children); //当前节点下是否有子节点
                        layer.open({
                            title: '课程表详细',
                            type: 2,
                            area: ['90%','90%'],
                            content: '{% url "xyss_admin:majorSlave"%}?mater_id=' + obj.data.id
                        });
                   }
                });
            }else{
                layer.msg(res['msg']);
            }
        },
        error: function(res) {
            console.log("失败了: " + res['msg']);
        }
  });

});
</script>
</html>